﻿using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Rmac.DataBase.Entity;
using Rmac.Service.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rmac.Controller.Config
{
    public class SysConfigController
    {
        [Inject]
        private SysConfigService _configService { set; get; }

        private static Func<SysConfig, Task<List<SysConfig>>> getConfigListFun;
        private static Func<String, Task<SysConfig>> getConfigByCodeFun;
        private static Func<SysConfig, Task<object>> updateConfigFun;


        public SysConfigController(SysConfigService configService) 
        { 
            _configService = configService;
            getConfigListFun = _configService.GetConfigList;
            getConfigByCodeFun = _configService.GetConfigByCode;
            updateConfigFun = _configService.UpdateConfig;
        }

        /// <summary>
        /// 获取参数列表
        /// </summary>
        /// <returns></returns>
        [JSInvokable]
        public async Task<List<SysConfig>> GetConfigList(SysConfig config)
        {
            return await getConfigListFun.Invoke(config);
        }


        /// <summary>
        /// 根据编码获取参数
        /// </summary>
        /// <returns></returns>
        [JSInvokable]
        public async Task<SysConfig> GetConfigByCode(string code)
        {
            return await getConfigByCodeFun.Invoke(code);
        }


        /// <summary>
        /// 更新参数
        /// </summary>
        /// <returns></returns>
        [JSInvokable]
        public async Task<object> UpdateConfigBy(SysConfig config)
        {
            return await updateConfigFun.Invoke(config);
        }
    }
}
